// MARK: - Tuple
let point = (x: 123, y: 321)
let x = point.x
let y = point.y
//print(x, y)

let (x1, _) = point
//print(x1)

func obtainPoint() -> (x: Int, y: Int) {
    return (x: 123, y: 321)
}
let p = obtainPoint()
//print(p.x, p.y)

// MARK: - Array
var array = [0, 1, 2, 3, 4, 5]
var slice = array[2...4]
//print(slice)
//print(slice[2]) // 下标和原array一致，slice的第1个下标是2，而不是0
//slice[2] = 666 // 不影响原array
//print(slice)
//print(array)
var anotherArray = Array(array[2...4])
//print(anotherArray)
//print(anotherArray[0]) // 新array有自己的下标了，第1个下标是0
anotherArray[0...1] = [6, 66, 666, 6666] // 范围替换
//print(anotherArray)
anotherArray.swapAt(0, anotherArray.count - 1)
//print(anotherArray)

var abcArray = ["a", "b", "c", "d", "e", "f", "g"]
//abcArray.forEach {
//    print($0)
//}
for (index, item) in abcArray.enumerated() {
//    print("\(index): \(item)")
}
//print(abcArray)
//print(abcArray.prefix(2))
//print(abcArray.suffix(2))
//let dropFirstSlice = abcArray.dropFirst(2)
//print(dropFirstSlice)
//print(abcArray)
//let dropLastSlice = abcArray.dropLast(2)
//print(dropLastSlice)
//print(abcArray)

var strings = ["AAA", "B", "CCCC", "DD"]
//print(strings)
strings.sort(by: { $0.count < $1.count })
//print(strings)


var numbers = [0, 1, 2, 3, 4, 5, 6]
//print(numbers)
//print(numbers.filter({ $0 % 2 == 0 }))
//print(numbers.map({ $0 * 2 }))
//print(numbers.reduce(0) { $0 + $1 })

var likeNumbers = ["0", "A", "2", "B", "3"]
//print(likeNumbers.map({ Int($0)})) // 返回Optional<Int>
//print(likeNumbers.compactMap({ Int($0)})) // 抛弃nil，返回Int

// MARK: - Dictionary
var dict = ["a": 0, "b": 1, "c": 2]
var emptyDict: [String: Int] = [:]
for (key, value) in dict {
//    print("\(key): \(value)")
}
let stocks = [0.5: 10, 1.0: 10, 1.5: 10, 2.0: 10]
//print(stocks.reduce(0) { $0 + $1.key * Double($1.value) })
//print(stocks.reduce(into: [], { (resultArray, item) in
//    resultArray.append(item.key)
//}))
//print(stocks.reduce(into: [], { $0.append($1.key * Double($1.value)) }))

// MARK: - Set
var set = Set([0, 0, 1, 1, 2, 3])
//print(set)
var anotherSet: Set<Int> = [0, 0, 1, 1, 2, 3]
//print(anotherSet)
